package com.example.securityproject.demos.utils;

import java.io.PrintWriter;
import javax.servlet.http.HttpServletResponse;
import com.fasterxml.jackson.databind.ObjectMapper;

public class ResponseUtil {

    public static void write(HttpServletResponse response,Object o)throws Exception{
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out=response.getWriter();
        out.println(o.toString());
        out.flush();
        out.close();
    }

    public static void writeJson(HttpServletResponse response,Object o)throws Exception{
        ObjectMapper om = new ObjectMapper();
//		om.writeValueAsString(o)代表了json串
        write(response, om.writeValueAsString(o));
    }
}
